package com.meessiom.train.crm.order.controller;

import com.meessiom.train.crm.order.model.OrderInfo;
import com.meessiom.train.crm.order.service.OrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@CrossOrigin("*")
@RestController
@RequestMapping("/api/v1/orders")
@Slf4j

public class OrderController {
    @Autowired
    private OrderInfoService orderInfoService;

    @GetMapping
    public List<OrderInfo> getAllOrders()
    {
        return orderInfoService.getAllOrders();
    }

    @PostMapping
    public OrderInfo createOrder(@RequestBody OrderInfo order)
    {
        return orderInfoService.createOrder(order);
    }



    @DeleteMapping({"id"})
    public ResponseEntity<HttpStatus> deleteStudent(@PathVariable long id) {
        orderInfoService.deleteOrder(id);

        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
}
